/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cassandrawindow;

/**
 *
 * @author ADMIN
 */
public class HandlePartition {
   /* private static String V3_BAN_DATE           = "v3_ban_date_cs";
    private static String V3_CAM_DATE           = "v3_cam_date_cs";
    private static String V3_CAM_HOURLY_CPC     = "v3_cam_hourly_cs";
    private static String V3_DOMAIN_DATE        = "v3_domain_date_cs";
    private static String V3_ZONE_DATE          = "v3_zone_date_cs";
    private static String V3_BAN_HOURLY_CS      = "v3_ban_hourly_cs";*/

    private static String V3_BAN_DATE           = "v3_ban_date";
    private static String V3_CAM_DATE           = "v3_cam_date";
    private static String V3_CAM_HOURLY_CPC     = "v3_cam_hourly";
    private static String V3_DOMAIN_DATE        = "v3_domain_date";
    private static String V3_ZONE_DATE          = "v3_zone_date";
    private static String V3_BAN_HOURLY_CS      = "v3_ban_hourly";
    private static String V3_CAM_IP             = "v3_cam_ip";
    
    public void handlePartition() {
        // TODO code application logic here
        String currentDate  = currentDate();
        //String currentDate  = "2013-02-22";
        MysqlDataManager67 mysql67 = new MysqlDataManager67();
        mysql67.updateSysDateCPC();
        mysql67.updateSysDateCPCForMoney();
        /*
         * add and drop partiton every table *_cs
         */
        mysql67.mergePartition(V3_DOMAIN_DATE, "5");
        mysql67.addPartition(V3_DOMAIN_DATE, currentDate);

        mysql67.mergePartition(V3_ZONE_DATE, "5");
        mysql67.addPartition(V3_ZONE_DATE, currentDate);
        
        mysql67.mergePartition(V3_BAN_DATE, "5");
        mysql67.addPartition(V3_BAN_DATE, currentDate);

        mysql67.mergePartition(V3_CAM_HOURLY_CPC, "5");
        mysql67.addPartition(V3_CAM_HOURLY_CPC, currentDate);

        mysql67.mergePartition(V3_CAM_DATE, "5");
        mysql67.addPartition(V3_CAM_DATE, currentDate);
       
        mysql67.mergePartition(V3_BAN_HOURLY_CS, "5");
        mysql67.addPartition(V3_BAN_HOURLY_CS, currentDate);
        
        mysql67.mergePartition(V3_CAM_IP, "5");
        mysql67.addPartition(V3_CAM_IP, currentDate);
        /*
         * update sys_date_cpc in 000_sys_params_CS
        */
        Debug.print("ok partiton");
    }

    public static String beforeDate()
    {
        String retDate = "";//2012-07-24
        String date = TimeUtil.getCurrentTimeInStringForLog();//yyyy/MM/dd H:mm:ss

        String[] arrTime        = new String[2];
        String[] firstArrTime   = new String[3];
        String[] secondArrTime  = new String[3];

        arrTime = date.split(" ");
        firstArrTime    = arrTime[1].split(":");
        secondArrTime   = arrTime[0].split("-");

        int day = Integer.valueOf(secondArrTime[2]) - 1;

        if(day < 10){
            retDate = secondArrTime[0]+"-"+secondArrTime[1]+"-"+"0"+String.valueOf(day);
        } else{
            retDate = secondArrTime[0]+"-"+secondArrTime[1]+"-"+String.valueOf(day);
        }

        return retDate;
    }


     public static String currentDate()
    {
        String retDate = "";//2012-07-24
        String date = TimeUtil.getCurrentTimeInStringForLog();//yyyy/MM/dd H:mm:ss
        String[] arrTime        = new String[2];
        String[] firstArrTime   = new String[3];
        String[] secondArrTime  = new String[3];
        arrTime = date.split(" ");
        firstArrTime    = arrTime[1].split(":");
        secondArrTime   = arrTime[0].split("-");
        retDate = secondArrTime[0]+"-"+secondArrTime[1]+"-"+secondArrTime[2];
        return retDate;
    }
}
